var express = require('express');
var router = express.Router();
var axios = require('axios');
var fs = require('fs');

router
    .get('/', async function (req, res, next) {
        // res.end('hello proxy');

        // axios 请求的返回值是一个 promise对象
        var response = await axios.get('https://www.duitang.com/napi/blog/list/by_filter_id/?include_fields=top_comments%2Cis_root%2Csource_link%2Citem%2Cbuyable%2Croot_id%2Cstatus%2Clike_count%2Csender%2Calbum%2Creply_count&filter_id=%E7%BE%8E%E9%A3%9F%E8%8F%9C%E8%B0%B1&start=24&_=1616113294942')
        // console.log(response.data);

        fs.writeFile('./data.json', JSON.stringify(response.data), function (err) {
            if (err) return console.error(err);
            console.log('数据转存成功！');
        });
        res.json(response.data);
    });




module.exports = router;